#include<iostream>
#include<cstring>
using namespace std;
typedef long long LL;
const int N = 3e5 + 10, M = N * 2, mod = 998244353;
int h[N], e[M], ne[M], idx;
int dis[N];
int f[N][23];
int n, m;
LL s[N][60];
LL mi[60];
void add(int a, int b)
{
	e[idx] = b, ne[idx] = h[a], h[a] = idx++;
}

void dfs(int u, int fa)
{
	for (int i = h[u]; ~i; i = ne[i]) {
		int j = e[i];
		if (j == fa)continue;
		dis[j] = dis[u] + 1;
		f[j][0] = u;
		for (int k = 1; (1 << k) <= dis[j]; k++) {
			f[j][k] = f[f[j][k - 1]][k - 1];
		}
		mi[0] = 1;
		for (int z = 1; z <= 50; z++) {
			mi[z] = mi[z - 1] * dis[j] % mod;
			mi[z] %= mod;
			//cout << "mi[z]==" << mi[z] << endl;
		}
		for (int z = 1; z <= 50; z++) {
			s[j][z] = (s[u][z] + mi[z]) % mod;
			s[j][z] %= mod;
			//cout << "s[z]==" << s[u][z] << endl;
		}
		dfs(j, u);
	}
}

int lca(int a, int b)
{
	if (dis[a] < dis[b])swap(a, b);
	int d = dis[a] - dis[b];
	for (int i = 0; d; i++) {
		if (d & 1)a = f[a][i];
		d /= 2;
	}
	if (a == b)return a;
	for (int i = 21; i >= 0; i--) {
		if (f[a][i] != f[b][i]) {
			a = f[a][i];
			b = f[b][i];
		}
	}
	return f[a][0];
}

int main()
{
	cin >> n;
	memset(h, -1, sizeof(h));
	for (int i = 1; i <= n - 1; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		add(u, v);
		add(v, u);
	}
	dfs(1, 0);
	/*for (int i = 1; i <= n; i++) {
		cout << dis[i] << endl;
	}*/
	cin >> m;
	while (m--) {
		int u, v, k;
		scanf("%d%d%d", &u, &v, &k);
		int x = lca(v, u);
		LL ans = (s[u][k] + s[v][k] - s[x][k] - s[f[x][0]][k] + 2 * mod) % mod;
		printf("%lld\n", ans);
	}
	return 0;
}